<template>
  <div class="app-container">
    <el-form :inline="true" :model="listQuery" class="demo-form-inline" @submit.native.prevent>
      <el-form-item label="订单号">
        <el-input v-model="listQuery.q_orderSn" size="small"></el-input>
      </el-form-item>
      <el-form-item label="换货状态">
        <el-select
          class="toolbar-lable-right"
          v-model="listQuery.q_state"
          placeholder="请选择" size="small"
        >
          <el-option
            v-for="item in stateReturn"
            :label="item.name"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="用户名">
        <el-input v-model="listQuery.q_memberName" size="small"></el-input>
      </el-form-item>
      <el-form-item label="商家">
        <el-select
          class="toolbar-lable-right"
          v-model="listQuery.q_sellerId"
          placeholder="请选择"
          size="small"
        >
          <el-option
            v-for="item in sellers"
            :label="item.name"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="this.getList">查询</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- <div class="button-table-margin">
      <el-button size="small" type="primary" @click="details">详情</el-button>
    </div> -->
    <el-table
      ref="singleTable"
      v-loading="listLoading"
      :data="dataList"
      border
      fit
      highlight-current-row
      @current-change="handleCurrentChange"
      style="width: 100%">
      <el-table-column
        type="index"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        label="商品名称"
        width="400"
        show-overflow-tooltip>
        <template slot-scope="scope">
          <div>
          <img width="80" height="80" :src="$imagePath+scope.row.masterImg" style="vertical-align: middle;">
          {{ scope.row.productName }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        property="sellerName"
        width="200"
        label="商家">
      </el-table-column>
      <el-table-column
        property="orderSn"
        width="200"
        label="订单号">
      </el-table-column>
      <el-table-column
        property="memberName"
        width="120"
        label="用户名">
      </el-table-column>
      <el-table-column property="number" width="100" label="换货数量"></el-table-column>
      <el-table-column property="question" width="300" label="问题描述"></el-table-column>
      <el-table-column property="changeName2" width="120" label="商家收件人"></el-table-column>
      <el-table-column property="phone2" width="120" label="商家收件电话"></el-table-column>
      <el-table-column property="addressAll2" width="150" label="商家省市区"></el-table-column>
      <el-table-column property="addressInfo2" width="200" label="商家地址"></el-table-column>
      <el-table-column property="logisticsName2" width="150" label="商家物流公司"></el-table-column>
      <el-table-column property="logisticsNumber2" width="150" label="商家快递单号"></el-table-column>
      <el-table-column property="optName" width="150" label="处理人"></el-table-column>
      <el-table-column
        property="state"
        width="150"
        label="换货状态">
        <template slot-scope="scope">
          {{ codeBox.MEM_PROD_EXCHG_STATE[scope.row.state] }}
        </template>
      </el-table-column>
      <el-table-column
        property="createTime"
        width="200"
        label="创建时间">
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="70" align="center">
        <template slot-scope="scope">
          <el-button @click="detailsRow(scope.row.id)" type="text" size="small">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>

<script>
import { listProductExchange, getSellers, detailsProductExchange } from '@/api/orderafter'
import Pagination from '@/components/Pagination'
import { Message } from 'element-ui'
import { getCodeManager,codeToArray} from '@/api/all'
export default {
  name: 'exchangelist',
  components: { Pagination },
  data() {
    return {
      dataList: [],
      stateReturn: [],
      sellers: [],
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        q_orderSn: '',
        q_state: '',
        q_memberName: '',
        q_sellerId: ''
      }
    }
  },
  created() {
    getCodeManager('MEM_PROD_EXCHG_STATE', () => {
      this.stateReturn = codeToArray('MEM_PROD_EXCHG_STATE');
    })
    this.getList()
    getSellers().then(response => {
      this.sellers=[
        ...response.data.rows.map((item)=>{return  {
          name:item.sellerName,
          value:item.id
        }})
      ]
    })
  },
  methods:{
    handleCurrentChange(val) {
      // 选中当前行数据
      this.currentRow = val
    },
    // 获取列表数据
    getList() {
      this.listLoading = true
      listProductExchange(this.listQuery).then(response => {
        this.dataList = response.data.rows
        this.total = response.data.total
        this.listLoading = false
      })
    },
    reset() {
      this.listQuery = {
        page: 1,
        limit: 20,
        q_orderSn: '',
        q_state: '',
        q_memberName: '',
        q_sellerId: ''
      }
      this.getList()
    },
    detailsRow(id){
      this.$router.push({
        path: "/orderafter/exchangedetails",
        query: { id: id }
      });
    }
  }
}
</script>

<style>
</style>
